<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
	<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%@ include file="../../common/base.jsp"%>
<%
	response.setCharacterEncoding("utf-8");
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Insert title here</title>
<link href="${path }/dist/css/bootstrap.css" rel="stylesheet">
<link href="${path }/dist/css/bootstrap-overrides.css" rel="stylesheet">

<!-- Button -->
<link href="${path }/dist/css/compiled/elements.css" rel="stylesheet">
<!-- libraries -->
<link rel="stylesheet" type="text/css"  href="${path }/dist/css/font-awesome.css">
<!-- this -->
<link rel="stylesheet" type="text/css" href="${path }/dist/css/app.css">
<!-- 右键菜单插件 -->
<link rel="stylesheet" type="text/css" href="${path }/dist/css/smartMenu.css">
<link rel="stylesheet" type="text/css" href="${path }/back/ifrom.css">


<script src="${path }/dist/js/jquery.min.js"></script>
<script src='${path }/dist/js/bootstrap.min.js'></script>
<script src='${path }/dist/js/jquery-smartMenu.js'></script>
<style type="text/css">
.nav-header {
	display: block;
	padding: 3px 15px;
	font-size: 11px;
	font-weight: bold;
	line-height: 20px;
	color: #999;
	text-shadow: 0 1px 0 rgba(255, 255, 255, 0.5);
	text-transform: uppercase;
}
#firstRow{
	padding: 3px;
}

.my_modal{
	position: absolute;
	height: 200px;
	width: 250px;
	display:none;
	left: 20%;
	top: 10%;
}
.my_input {
  
  width: 150px;
  height: 34px;
  padding: 6px 12px;
  font-size: 14px;
  line-height: 1.428571429;
  color: #555555;
  vertical-align: middle;
  background-color: #ffffff;
  border: 1px solid #cccccc;
  border-radius: 4px;
  -webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075);
  box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075);
  -webkit-transition: border-color ease-in-out .15s, box-shadow ease-in-out .15s;
  transition: border-color ease-in-out .15s, box-shadow ease-in-out .15s;
}
.my_input:focus {
  border-color: #66afe9;
  outline: 0;
  -webkit-box-shadow: inset 0 1px 1px rgba(0,0,0,.075), 0 0 8px rgba(102, 175, 233, 0.6);
  box-shadow: inset 0 1px 1px rgba(0,0,0,.075), 0 0 8px rgba(102, 175, 233, 0.6);
}
</style>
</head>
<body>
<div id="pad-wrapper">
	<div class="row head">
	<div class="col-md-12">
			<h3><%=new String(request.getParameter("type").getBytes("ISO-8859-1"),"UTF-8") %></h3>
			</div>
	</div>
	<div class="row">
		<div class="panel panel-success">
				<div class="panel-heading" >
				
				<span>请使用左键菜单操作</span>
				</div>
			<div class="panel-body">
				<form action="" id="list_page_form" method="post">
				<ul class="list-group" id="list_page">
					<li class="list-group-item" style="display: none" id="firstRow">
						<input type="text" class="form-control input-sm" placeholder="print：" name="measurebean.measure_name" value=""
						maxlength=15/>
						<input type="hidden" name="measurebean.measure_type" value="<%=new String(request.getParameter("type").getBytes("ISO-8859-1"),"UTF-8") %>">
					</li>
					<c:forEach var="wal" items="${basisList }">
				    	<li class="list-group-item" data-id="${wal.measure_id }">${wal.measure_name }</li>
					</c:forEach>
					<c:if test="${fn:length(basisList)==0}">
						<li class="list-group-item no_record">没有记录，右键新增</li>
					</c:if>
				</ul>
				</form>
			</div>
		</div>
	</div>
</div>
	<div class="my_modal" id="edit_measure">
	<form action="" method="post" id="edit_measure_form">
	    <div class="modal-content ">
	      <div class="modal-header">
	        <button type="button" class="close" data-dismiss="modal" aria-label="Close" onclick="hideMenu()"><span aria-hidden="true">&times;</span></button>
	        <h4 class="modal-title" id="myModalLabel">修改<%=new String(request.getParameter("type").getBytes("ISO-8859-1"),"UTF-8") %></h4>
	      </div>
	      <div class="modal-body">
	       	
	       		<p><span style="color: #f00;">*</span>名称：<input type="text" name="measurebean.measure_name" maxlength="12" class="my_input"/><br>(最多6个字母或3个汉字)</p>
	       		<input type="hidden" name="measurebean.measure_id">
	       
	      </div>
	      <div class="modal-footer">
	        <button type="button" class="btn btn-default" onclick="hideMenu()">Close</button>
	        <button type="button" class="btn btn-primary" id="edit_measure_form_submit">确认提交</button>
	      </div>
	    </div>
	  </form>
</div>
<script type="text/javascript">
var liMenuData=[
                [{text: "新增", func:add },
                 {text: "修改", func:edit },
                 {text: "删除", func:remove },
                ],[{text: "完成", func:confirm_submit}]
               ]
$(document).ready(function() {
	$("#list_page>li").smartMenu(liMenuData,{name:"limenu"});
	//$("#btnAdd").bind("click", addRole);
	$("#edit_measure_form_submit").click(function(e){
		if(verif($(this).closest("form"))){
			var from_data=$(this).closest("form").serializeArray();
			var saveURL = "${path}/back/basis!edit?date="+new Date()+"";
			jQuery.post(saveURL,from_data,function(jsonData){
				if(jsonData.info){
						alert(jsonData.text);
					 window.location.reload();
				}else{
					alert("添加失败：原因\n"+jsonData.text);
				}
			},"json");
		}
	});
});

function add(){
	var whichEl = $("#firstRow");
	if (whichEl.css("display") == "none") {
		whichEl.slideDown("slow");
		whichEl.find("input[name='measurebean.measure_name']").focus();
	}else{
		whichEl.slideUp();
	}
}
function edit(){
	if($(this).hasClass('no_record')){
		alert("别闹，这又不是记录")
		return ;
	}
	$("#edit_measure input[type='text']").val($(this).html());
	$("#edit_measure input[type='hidden']").val($(this).data("id"));
	var cityObj = $(this);
	var cityOffset = cityObj.offset();
	$("#edit_measure").css({left:cityOffset.left+100 + "px", top:cityOffset.top-100 + "px"});
	$("#edit_measure").fadeIn("fast");
	$("body").bind("mousedown", onBodyDown);
}
function remove(){
	if(confirm("确认删除单位：\""+$(this).html()+"\"  吗")){
		var from_data=[{name:"measurebean.measure_id",value:$(this).data("id")}];
  		var saveURL = "${path}/back/basis!deletl?date="+new Date()+"";
		jQuery.post(saveURL,from_data,function(jsonData){
			if(jsonData.info){
				alert("删除成功");
				 window.location.reload();
			}else{
				alert("删除失败：原因\n"+jsonData.text);
			}
		},"json");
	}else 
		return ;
}
function confirm_submit(){
	if(verif(this)){
		var from_data=$(this).closest("form").serializeArray();
		var saveURL = "${path}/back/basis!add?date="+new Date()+"";
		jQuery.post(saveURL,from_data,function(jsonData){
			if(jsonData.info){
					alert(jsonData.text);
				 window.location.reload();
			}else{
				alert("添加失败：原因\n"+jsonData.text);
			}
		},"json");
	}
}
function verif(obj){
	var name=$("input[type='text']",$(obj)).val();
	var type=$("input[type='hidden']",$(obj)).val();
	if(name!=null&&""!=name&&null!=type&&""!=type){
		return true;
	}
	alert("检查到参数为空，请确认");
	return false;
}
//增加角色按钮
function addRole() {
	var whichEl = $("#firstRow");
	if (whichEl.css("display") == "none") {
		whichEl.slideDown("slow");
		$("#btnAdd").html("Cance New");
		whichEl.find("input[name='measurebean.measure_name']").focus();
	} else {
		whichEl.slideUp();
		$("#btnAdd").html("Add measure");
	}
}
function onBodyDown(event) {
	//alert();
	if (!($(event.target).parents("#edit_measure").length>0)) {
		hideMenu();
	}
}
//解除 body绑定
function hideMenu() {
	$("#edit_measure").fadeOut("fast");
	$("body").unbind("mousedown", onBodyDown);
}
</script>
</body>
</html>